/*
 * Copyright 2007 National Bioinformatics Network
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
/**
 * 
 */
package dgbgui.gui.widgets;


import java.awt.Color;

import junit.framework.TestCase;
/**
 * @author bjnortier
 * Testing of Widget (confined to testing the the fill and strok colour hierarchy)
 */
public class WidgetTest  extends TestCase {

    protected void setUp() throws Exception {
        m_a = new Widget(null);
        m_b = new Widget(m_a);
        m_c = new Widget(m_b);
    }

    protected void tearDown() throws Exception {
    }
    
    public void testDefaults() throws Exception { 
        assertTrue( m_a.getStrokeColour().equals(Widget.getDefaultStrokeColour()));
        assertTrue( m_a.getFillColour().equals(Widget.getDefaultFillColour()));
        
        Color newColor = Widget.getDefaultStrokeColour().brighter();
        m_a.setStrokeColor( Widget.getDefaultStrokeColour());
        assertFalse( m_a.getStrokeColour().equals(newColor));
        
        newColor = Widget.getDefaultFillColour().darker();
        m_a.setFillColor( Widget.getDefaultFillColour());
        assertFalse( m_a.getFillColour().equals(newColor));
    }
    
    public void testHierarchy() throws Exception {
        
        // If a colour is set on A, then the stroke and fill colour
        // from C and B should be those of A
        Color newCol1 = new Color(Color.HSBtoRGB((float)(Math.random()*255), 0.4f, 0.8f));
        Color newCol2 = new Color(Color.HSBtoRGB((float)(Math.random()*255), 0.4f, 0.8f));
        
        m_a.setStrokeColor(newCol1);
        m_a.setFillColor(newCol2);
        
        assertTrue(m_b.getFillColour() == m_a.getFillColour());
        assertTrue(m_b.getStrokeColour() == m_b.getStrokeColour());
        assertTrue(m_c.getFillColour() == m_a.getFillColour());
        assertTrue(m_c.getStrokeColour() == m_b.getStrokeColour());
        
        // If we set a stroke colour on B, C should still use A's fill colour
        Color newCol3 = new Color(Color.HSBtoRGB((float)(Math.random()*255), 0.4f, 0.8f));
        m_b.setStrokeColor(newCol3);
        
        assertTrue(m_c.getFillColour() == m_a.getFillColour());
        assertTrue(m_c.getStrokeColour() == m_b.getStrokeColour());
    }
    
    Widget m_a, m_b, m_c;

}
